
#include "download_app.h"
#include "first_title.h"
#include "pt_fs.h"
#include "pt_dev.h"
#include "sys_font.h"

static void btn_event_callback(lv_event_t* event)
{
    switch(event->code){
    case LV_EVENT_CLICKED:
    {
        debug_d("clicked\n");

        page_install("add_dev",lv_page_add_dev_create(),NULL);
        page_push_anim("add_dev",LOAD_ANIM_MOVE_LEFT);

        break;
    }
    default:break;
    }

    return ;
}

void ui_init_download_app_page_src(lv_obj_t *superview)
{
    first_title_create();

    first_title_set(FIRST_PAGE_DOWNLOAD,0,1);
    //****************************************************** */
    lv_obj_t * qr = lv_qrcode_create(superview,135,lv_color_make(0xff,0xff,0xff),lv_color_make(0x0,0,0));
    
    // char * txt = "https://qrcode.midea.com/index.html?v=5&mode=003&dsn=0000E65182761014G39131A00058&SSID=midea_e2_0058"; //COLOM 
    // char * txt = "https://qrcode.midea.com/index.html?v=5&mode=003&dsn=0000E3518511018CE39131A00058&SSID=midea_e3_0058"; //美居

    char qrcode_txt[110] = {0};
    char *qrcode_sn  =  malloc(29);
    
    snprintf(qrcode_sn,29,"%s","aaaaaaaaaaa");

    qrcode_sn[28] = '\0';

    sprintf(qrcode_txt,  "https://qrcode.midea.com/index.html?v=5&mode=003&dsn=%s&SSID=midea_e3_0058" ,qrcode_sn);
    // debug_d("qrcode_txt:%s,%d\n",qrcode_txt,strlen(qrcode_txt));

    lv_obj_set_pos(qr,72,69);
    lv_qrcode_update(qr,qrcode_txt,strlen(qrcode_txt));
    //****************************************************** */
    lv_obj_t * label = lv_label_create(superview);
    lv_obj_set_style_text_font( label, lv_font_get(28), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(label,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(label,LV_OPA_80,0);
    lv_label_set_text( label, "扫码下载\n美的美居APP");
    lv_obj_set_pos(label,246,106);
    //****************************************************** */

    lv_obj_t * btn = lv_btn_create(superview);
    lv_obj_set_style_radius(btn, LV_PCT(25), LV_PART_MAIN);
    lv_obj_set_style_outline_width(btn, 0, LV_PART_MAIN);
	lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN);
    lv_obj_set_style_bg_color(btn,lv_color_make(0x26,0x7a,0xff),0);
    lv_obj_set_style_bg_opa(btn,LV_OPA_100,0);
    lv_obj_set_pos(btn,52,250);
    lv_obj_set_size(btn,350,50);

    lv_obj_add_event_cb(btn,btn_event_callback,LV_EVENT_ALL,NULL);
    //*******************************************************************/

    lv_obj_t * btn_label = lv_label_create(btn);
    lv_obj_set_style_text_font( btn_label, lv_font_get(24), LV_STATE_DEFAULT );
    lv_label_set_text(btn_label,"已安装，下一步");
    lv_obj_center(btn_label);
     //*******************************************************************/

}

static void download_app_page_on_custom_attr_config(page_base_t* self)
{
    return ;
}
static void download_app_page_on_view_load(page_base_t* self)
{
    ui_init_download_app_page_src(self->root);
    return ;
}
static void download_app_page_on_view_did_load(page_base_t* self)
{
    return ;
}
static void download_app_page_on_view_will_appear(page_base_t* self)
{
    return ;
}
static void download_app_page_on_view_did_appear(page_base_t* self)
{
    return ;
}
static void download_app_page_on_view_will_disappear(page_base_t* self)
{
    return ;
}
static void download_app_page_on_view_did_disappear(page_base_t* self)
{
    return ;
}
static void download_app_page_on_view_did_unload(page_base_t* self)
{
    return ;
}


static page_vtable_t page_param = {
    .on_custom_attr_config  = download_app_page_on_custom_attr_config,
    .on_view_load           = download_app_page_on_view_load,
    .on_view_did_load       = download_app_page_on_view_did_load,
    .on_view_will_appear    = download_app_page_on_view_will_appear,
    .on_view_did_appear     = download_app_page_on_view_did_appear,
    .on_view_will_disappear = download_app_page_on_view_will_disappear,
    .on_view_did_disappear  = download_app_page_on_view_did_disappear,
    .on_view_did_unload     = download_app_page_on_view_did_unload,
};


page_vtable_t* lv_page_download_app_create(void)
{
    return &page_param;
}
